#ifndef PARTICLE_H
#define PARTICLE_H

#include "ParticleSwarm.h"
#include <random>

using namespace std;

class ParticleSwarm;

class Particle
{
public:
	//------------------------------------------------------
	///	Swarm
	ParticleSwarm* Swarm;
	vector<double> pPosition;
	vector<double> pVelocity;
	vector<double> pBestPosition;
	double pCost;

	//------------------------------------------------------
	Particle();
	Particle(ParticleSwarm* swarm, vector<double> position, vector<double> velocity);
	~Particle();

	//------------------------------------------------------
	///	Calculate the cost (fitness)
	void update_Data(double pCostValue,bool forceUpdate);

	//------------------------------------------------------
	// Update the personal best cost and position of a particle
	void UpdatePBest();

	//------------------------------------------------------
	/// Update the velocity and Position of a particle
	void UpdateVelocityAndPosition(vector<double> bestPositionOfSwarm);

protected:
	double pBestCost;		// Personal best cost (fitness) of the particle

	//Random _rnd;
private:
	//------------------------------------------------------
	// Max range
	double Max(vector<double> position);

	//------------------------------------------------------
	// Min range
	double Min(vector<double> position);

	/// Random number generator 
	std::random_device rd;
	std::mt19937 gen;
	std::uniform_real_distribution<> uniDis;
};

bool CompareTo(const Particle* p1, const Particle* p2);
#endif